﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.DAO;
using ClassLibrary.Utilities;

public partial class en_ucControl_l : System.Web.UI.UserControl
{
    TblAccountsDAO userDAO = new TblAccountsDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        bool bFlag = false;
        try
        {
            TblAccounts userAccount = userDAO.GetUser(txtusername.Text.Trim(), Encryption.EncryptToString(txtpass.Text));
            if (userAccount != null)
            {            
                    if (userAccount.IDAcc > 0)
                    {
                        Session[Global.SESSION_LOGGED_USER] = userAccount;
                        bFlag = true;

                    }
                    else
                    {
                        lblMessage.Text = "Username or password is incorrect.";
                       
                    }
            }
            else
            {
                lblMessage.Text = "Username is Invalid .";
                lblMessage.Visible = true;
            }
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (bFlag)
        {
            ScriptManager.RegisterStartupScript(btnLogin, btnLogin.GetType(), "ScriptLoginSuccess", "UpdateParentsLogin();", true);
            //ScriptManager.RegisterStartupScript(cmdLogin, cmdLogin.GetType(), "ScriptLoginSuccess", "UpdateParentsLogin();", true);
            //Response.Redirect(string.Format("~/en/ManagerPhotos.aspx"), true);
        }
    }
}
